﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YunCMS.Common;
using YunCMS.Core.Configration;

namespace YunCMS.Web.Admin.Settings
{
    public partial class SiteParams : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SiteConfig config = new SiteConfig();
                FillControls(config);
            }
        }

        private void FillControls(SiteConfig config)
        {
            CopyrightTB.Text = config.Copyright;
            KeywordsTB.Text = config.Keywords;
            DescTB.Text = config.Description;
            CompanyNameTB.Text = config.Company;
            TitleTB.Text = config.Title;

            emailfromTB.Text = config.EmailFrom;
            emailnicknameTB.Text = config.EmailNickName;
            emailportTB.Text = config.EmailPort;
            emailstmpTB.Text = config.EmailSMTP;
            emailusernameTB.Text = config.EmailAccount;
        }

        private void FillModel(SiteConfig config)
        {
            config.Copyright = CopyrightTB.Text.Trim();
            config.Keywords = KeywordsTB.Text.Trim();
            config.Description = DescTB.Text.Trim();
            config.Company = CompanyNameTB.Text.Trim();
            config.Title = TitleTB.Text.Trim();

            config.EmailFrom = emailfromTB.Text.Trim();
            config.EmailNickName = emailnicknameTB.Text.Trim();
            config.EmailPort = emailportTB.Text.Trim();
            config.EmailSMTP = emailstmpTB.Text.Trim();
            config.EmailAccount = emailusernameTB.Text.Trim();
        }

        private void Save()
        { 
            SiteConfig config = new SiteConfig();
            FillModel(config);
            config.Save();
        }

        protected void saveBt_Click(object sender, EventArgs e)
        {
            Save();
        }
    }
}